package projectmanagement.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import projectmanagement.model.dao.PersonDao;

public class DeletePersonController extends SimpleFormController {
	public static final String PERSON_ID = "id";

	private PersonDao personManager;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String id = request.getParameter(PERSON_ID);

		if (id != null && id.trim().length() > 0) {
			personManager.remove(Integer.parseInt(id));
		} else {
			throw new ServletException("Blogai nurodytas id.");
		}

		return new ModelAndView(getSuccessView());
	}

	public PersonDao getPersonManager() {
		return personManager;
	}

	public void setPersonManager(PersonDao personManager) {
		this.personManager = personManager;
	}

}
